/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import entities.Submission;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author ryuju
 */
@Stateless
public class SubmissionFacade extends AbstractFacade<Submission> {
    @PersistenceContext(unitName = "PASS-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public SubmissionFacade() {
        super(Submission.class);
    }
    
    public List<Submission> findByAssignment(Long asmtID)
    {
        ArrayList<Submission> ret = new ArrayList<Submission>();
        List<Submission> submitList = findAll();
        
        for(Submission submit : submitList)
        {
            if(submit.getAssignmentID().equals(asmtID))
            {
                ret.add(submit);
            }
        }
        return ret;
    }
    
    public List<Submission> findByUserLoginName(String name)
    {
        ArrayList<Submission> ret = new ArrayList<Submission>();
        List<Submission> submitList = findAll();
        
        for(Submission submit : submitList)
        {
            if(name.equals(submit.getUserLoginName()))
            {
                ret.add(submit);
            }
        }
        return ret;
    }

}
